Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JSON string in defaultImage field for overriding pipeline specific images in the mappings #293

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

RUFFY-369
Copy link
Collaborator

Towards closing 'livepeer/bounties/#69

This PR adds support for processing JSON string in defaultImageand specifies pipeline-specific images as key-value pairs with their mappings being updated to override containerImage.

go-livepeer PR which it supports is #3284

cc @rickstaa

@RUFFY-369 RUFFY-369 requested a review from rickstaa as a code owner November 28, 2024 16:07
worker/docker.go Outdated Show resolved Hide resolved
@rickstaa rickstaa force-pushed the update/ai-runner-image-flag-support branch from 3e48a78 to 57b5ef7 Compare January 22, 2025 21:02
This commit expands the test coverage to ensure more robust behavior and
refactors the `overridePipelineImages` function to improve error
handling and readability.
@rickstaa rickstaa force-pushed the update/ai-runner-image-flag-support branch from 57b5ef7 to aca9cc8 Compare January 22, 2025 21:04
Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as it works, but I suggested some code changes. I'll open a separate branch to share with you to facilitate.

worker/docker.go Outdated

// Handle JSON format for multiple pipeline images.
var imageMap map[string]string
if err := json.Unmarshal([]byte(imageOverrides), &imageMap); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT of implementing a simple "json flag" abstrraction like this? There are some advantages:

  • Clearer error handling. If the JSON is bad it will fail on startup, not here
  • Cleaner logic here, no need to handle parsing
  • Minor: A bit more performant since we're not parsing the flag every time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: Just saw that this inline edits the consts declared in this file. I'd say that's a sub-ideal since we now have consts that are not really the values that might be used in runtime. Some of the advantages I made above don't make sense as I guess this logic is run only once, so nevermind the JSON flag if you stay with this approach.

OTOH I think mutating the static variables can be a little error prone and harder to understand/debug. We now have "consts" in the file that are not really what might be used in runtime. A cleaner logic IMO would be to hold on to the override map in the docker manager instead, and change the getContainerImageName function to handle the override map instead. I think the logic might be simpler to understand as well. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point and solution thanks!

worker/docker.go Outdated
Comment on lines 84 to 93
if pipeline == "base" {
defaultBaseImage = image
continue
}

// Check and update the pipeline images.
if _, exists := pipelineToImage[pipeline]; exists {
pipelineToImage[pipeline] = image
} else if _, exists := livePipelineToImage[pipeline]; exists {
livePipelineToImage[pipeline] = image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the override JSON format could be improved to avoid multiple conflicts here. We have 3 different identifiers as keys on the same map:

  • the special base image name which is used as the default here
  • the batch pipeline image names (which comes from the pipeline_id)
  • the live pipeline image names (which comes from the model_id)

All of these values could conflict with each other. I think we could have a layered JSON and avoid this, like:

type ImageOverrides struct {
    Default string
    Batch map[string]string
    Live map[string]string
}

Then we access each of them independently. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it 😍. I did briefly have just this but then removed it again to keep changes minimal.

@victorges
Copy link
Member

@rickstaa here's a branch with my suggested changes: aca9cc8...vg/update/ai-runner-image-flag-support

Keep in mind I only updated docker.go, but not the tests. If you agree with the change would you mind updating the tests as well?

@rickstaa
Copy link
Member

@rickstaa here's a branch with my suggested changes: aca9cc8...vg/update/ai-runner-image-flag-support

Keep in mind I only updated docker.go, but not the tests. If you agree with the change would you mind updating the tests as well?

Thanks will do!

This commit ensures the tests are compatible with the new image
overrides behavoir.
This commit enhances the worker tests by introducing cases to verify the
behavior of image overrides.
rickstaa added a commit to RUFFY-369/go-livepeer that referenced this pull request Jan 23, 2025
…des`

This commit introduces deprecation logic for the `aiRunnerImage` flag, replacing
it with a new `aiRunnerImageOverrides` flag. The new flag is designed to support
enhanced image override functionality as implemented in the worker logic
in [ai-worker PR livepeer#293](livepeer/ai-worker#293).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants